CREATE PROCEDURE [dbo].[p_updatekind] 
  @value varchar(60),
  @kind int
AS
begin
  declare @kid int, @kindname varchar(60)
  if not exists(select * from ts_kind where kind=@kind and iscustom=1)
    return
  
  if exists(select * from ts_kind where kind=@kind and kname=@value)
    return

  select top 1 @kid=kid+1, @kindname=kindname from ts_kind where kind=@kind order by kid desc
  insert into ts_kind (kid,kind,kindname,kname,issys,iscustom) values (@kid,@kind,@kindname,@value,0,1) 
end